
package com.yupi.yupicturebackend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate() {
        // 使用 HttpComponentsClientHttpRequestFactory 替代默认的 SimpleClientHttpRequestFactory
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();

        // 设置连接超时时间（毫秒）
        factory.setConnectTimeout(5000); // 5秒

        // 设置读取超时时间（毫秒）
        factory.setReadTimeout(30000);  // 30秒

        return new RestTemplate(factory);
    }
}